﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Entity;
using System.Web;
using NLBS.Views;
using NLBS.Data.Business;

namespace NLBS.Validate
{
   public class ArticleValidate:ValidateTemplete<Article>
    {
       private IPostArticleView articleAction;

        public override void checkPower()
        {
            //判断是否登录
            if (!HttpContext.Current.Request.IsAuthenticated)
            {
                this.Error = "没有登陆,请登陆";
                return;
            }
            //判断是否有权限
            if (power.Post < 2)
            {
                Error = "没有发布的权限";
                return;
            }
        }

        public override void checkArgument()
        {
            checkRequireField();
            
        }

        private void checkRequireField()
        {
            Article art = articleAction.currentArticle;
            string[] validfield = { art.CategoryID.ToString(), art.Title, art.Content0 };
            foreach (string item in validfield)
            {
                if (String.IsNullOrEmpty(item.Trim()))
                {
                    Error += "请填写所有必填栏目.";
                }
            }
        }

        public void checkCategory()
        {
            Article art = articleAction.currentArticle;
            Category cat = CategoryData.GetCategoryByID(art.CategoryID);
            if (cat == null)
            {
                Error += "分类不存在.";
            }
            if (art.Title.Trim().Length < 1 || art.Title.Trim().Length > 255)
            {
                Error += "标题长度在1-255之间.";
            }

        }

        public override void checkEntity()
        {
            throw new NotImplementedException();
        }

        public override void checkPowerAgain()
        {
            throw new NotImplementedException();
        }
    }
}
